package com.sd.repay.controller;

import com.sd.repay.cache.SysConfig;
import com.sd.repay.common.Constants;
import com.sd.repay.utils.JsonUtil;
import com.sd.repay.utils.StringUtil;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * Created by sd on 2018/08/21
 * 分享相关控制类
 */
@Controller
@RequestMapping(value = "/shareMgr")
public class ShareController {

    private static final Logger log = LoggerFactory.getLogger(ShareController.class);

    /**
     * H5注册页面
     *
     * @return
     */
    @RequestMapping(value = "/shareRegUrl")
    public String shareRegUrl(HttpServletRequest request, @RequestParam Map<String, String> params) {

        log.info("分享H5注册页面接受参数[{}]", JsonUtil.objectToJson(params));
        String parentMerNo = params.get("parentMerNo");
        String oemType = params.get("oemType");
        oemType = StringUtils.isBlank(oemType) ? Constants.DEFAULT_OEM_TYPE : oemType;

        if(StringUtil.isBlank(parentMerNo)){
            request.setAttribute("error", "分享码不能为空");
            return "error";
        }
        String signKey = SysConfig.value("CLIENT_SIGN_KEY");
        request.setAttribute("signKey", signKey);
        request.setAttribute("parentMerNo", parentMerNo);
        request.setAttribute("oemType", oemType);
        return "H5/shareMerReg";
    }
}
